﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace HelpDesk.Models
{
    public class Ticket
    {

       
        private static HelpDeskDbContext _db =  HelpDeskDbContext.Instance;


        [Key]
        public int TicketID { get; set; }

        [Display(Name = "Ticket Title")]
        [Required]
        public string Title { get; set; }

        [Display(Name = "Ticket Description")]
        [Required]
        public string Description { get; set; }

        [Display(Name = "Created Date")]
        [Required]
        public DateTime Created { get; set; }

        [Required]
        public virtual UserProfile Customer { get; set; }

        public virtual List<Activity> Activities { get; set; }

        [Display(Name = "Completion Date")]
        public DateTime CompletionDate { get; set; }
        
        [Display(Name = "Proposed Completion Date")]
        [Required]
        public DateTime ProposedCompletionDate { get; set; }


        [Display(Name = "Support Staff")]
        public virtual UserProfile SupportStaff { get; set; }


        [Display(Name = "Ticket Priority")]
        [Required]
        public virtual TicketPriority Priority { get; set; }

        [Display(Name = "Ticket Status")]
        [Required]
        public virtual TicketStatus Status { get; set; }


        public static Ticket GetTicketByID(int intTicketID)
        {
            var ticket = _db.Tickets.Find(intTicketID);
            return ticket as Ticket;
           
        }


        public static List<Ticket> GetAllTickets()
        {
            var tickets = (from t in _db.Tickets
                           select t).ToList<Ticket>();
            return tickets;

            
        }

        //public static List<Ticket> GetTicketsByStatus(TicketStatus ticketStatus)
        //{
           
        //        var tickets = (from t in _db.Tickets
        //                       where t.Status == ticketStatus
        //                       select t).ToList<Ticket>();
        //        return tickets;
           
        //}

        public static List<Ticket> GetTicketsBySupportStaffID(int intUserProfileID)
        {
            
                var tickets = (from t in _db.Tickets
                               where t.SupportStaff.UserId == intUserProfileID
                               select t).ToList<Ticket>();
                return tickets;
            
        }

        public static List<Ticket> GetTicketsByCustomerID(int intUserProfileID)
        {
            
                var tickets = (from t in _db.Tickets
                               where t.Customer.UserId == intUserProfileID
                               select t).ToList<Ticket>();
                return tickets;
            


        }

        

       

       
    }
}